package com.tangkun.environment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.tangkun.environment.R;
import com.tangkun.environment.entity.gongzuo.PatientsReturn;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

/**
 * @author tangkun
 * @ClassName: HealthButlerAdapter
 * @Description: 搜索咨询列表适配器
 * @date 2016-08-20 上午11:57:36
 */
public class SearchZiXunAdapter extends BaseAdapter {

    private Context context;
    private List<PatientsReturn.Patients.ItemsBean> listData = new ArrayList<PatientsReturn.Patients.ItemsBean>();

    /**
     * @param context
     * @param listData
     */
    public SearchZiXunAdapter(Context context, List<PatientsReturn.Patients.ItemsBean> listData) {
        this.context = context;
        this.listData = listData;
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int i) {
        return listData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_search_zixun, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (listData != null) {

            // 点击跳转聊天
            convertView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
//                    //跳转聊天页面 会诊
//                    Intent intent = new Intent(v.getContext(), ChatActivity.class);
//                    intent.putExtra(EaseConstant.EXTRA_USER_ID, listData.get(position).easemobGroupId);//userId 群组ID
//                    intent.putExtra(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_GROUP);//chatType 群聊
//                    intent.putExtra(EaseConstant.EXTRA_USER_NICK, "讨论组" + listData.get(position).id);//群名称
//                    intent.putExtra(EaseConstant.EXTRA_ID, listData.get(position).id);//群拥有者ID
//                    intent.putExtra(EaseConstant.EXTRA_OWNER_ID, listData.get(position).owner.id);//群拥有者ID
//                    intent.putExtra(EaseConstant.EXTRA_ISCONSULTATION, "1");////会诊 “1”，  非会诊“0”
//                    v.getContext().startActivity(intent);
                }
            });
        }
        return convertView;

    }

    static class ViewHolder {

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
